$(function () {
  var App = {

    //TODO: Find a better way to set these from config.php
    baseUrl : '/zwop/',
    maxCharacters : 320,
    key_aoColumns : [
                { "mData": "key_bank_type"},
                { "mData": "key_bank_name" },
                { "mData": "key_user" },
                { "mData": "key_number" },
                { "mData": "key_cert_number" },
                { "mData": "key_cert_starttime" },
                { "mData": "key_cert_endtime" },
                { "mData": "key_keeper" },
                { "mData": "key_ip" },
                { "mData": "key_note" }             
                ],
    policy_aoColumns : [
                { "mData": "policy_bank_type"},
                { "mData": "policy_bank_name" },
                { "mData": "policy_bank_ip" },
                { "mData": "policy_bank_port" },
                { "mData": "policy_bank_proto" },
                { "mData": "policy_bank_idc" },
                { "mData": "policy_bank_nat" },
                { "mData": "policy_bank_line" },
                { "mData": "policy_bank_note" },
                ],
    port_aoColumns : [
                { "mData": "nc_bank_type"},
                { "mData": "nc_bank_name" },
                { "mData": "nc_listen_port" },
                { "mData": "nc_note" },
                ],
    init: function () {
      this.setElements();
      var nc_flag = $.trim(document.getElementById("ncFlag").textContent);
      if(nc_flag == "nc_key"){
            initTable(this.$keyTable,key_aoColumns);
      }else if(nc_flag=="nc_policy"){
            console.log('nc_policy');
            initTable(this.$policyTable,policy_aoColumns);
      }else if(nc_flag=="nc_port"){
            console.log('nc_port');
            initTable(this.$portTable,port_aoColumns);
      }
    },

    // Cache all the jQuery selectors for easy reference.
    setElements: function () {
      //config operation
      this.$keyTable = $('#keyTable');
      this.$policyTable = $('#policyTable');
      this.$portTable = $('#portTable');
    },
    // init table
    initTable: function(tableID,objList){
        editor = tableID.dataTable({ 
                "bProcessing":true,
                "bStateSave":false,
                "bLengthChange":false,
                "language":{
                "search":"搜索",
                "paginate":{"previous":"上一页","next":"下一页"},
                "info":"当前页_PAGE_/_PAGES_",
                "infoEmpty":"暂无记录",
                "zeroRecords":"暂未找到数据"
                },
                "aoColumns":objList
                });
    },
    /**
     * Util method for blasting an error message on the screen.
     * @param error
     */
    alertError : function( error ) {
       var args = arguments;
       var msg = error.responseText;
    }

  };

  App.init();

});
